package com.lm.upms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lm.upms.api.entity.SysRoleMenu;
import com.lm.upms.mapper.SysRoleMenuMapper;
import com.lm.upms.service.SysRoleMenuService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 角色菜单关联关系
 *
 * @author lm
 * @date
 */
@Service
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuService {

    /**
     * 更新角色菜单
     *
     * @param roleId
     * @param menuIds
     * @return
     */
    @Override
    public Boolean saveRoleMenus(Integer roleId, List<String> menuIds) {
        List<SysRoleMenu> roleMenuList = menuIds
                .stream().map(menuId -> {
                    SysRoleMenu roleMenu = new SysRoleMenu();
                    roleMenu.setRoleId(roleId);
                    roleMenu.setMenuId(Integer.valueOf(menuId));
                    return roleMenu;
                }).collect(Collectors.toList());

        return this.saveBatch(roleMenuList);
    }

}